<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>

<!DOCTYPE html>
<html>
	<body class="page-content">
		<jsp:include page="../common/top.jsp"></jsp:include>
		<title>管理员列表</title>

		<div class="page-header">
			<h1>
				管理员列表
			</h1>
		</div>
		<div class="page-content-area" data-ajax-content="true">
		<div class="row">
			<div class="col-xs-12">
				<div class="row">
					<div class="col-xs-12">
						<div class="widget-box">
							<div class="widget-header widget-header-small">
								<h5 class="widget-title lighter">搜索栏</h5>
							</div>
		
							<div class="widget-body">
								<div class="widget-main">
									<form id="_form" class="form-inline">
										<label>
											<label class="control-label" for="form-field-1"> 登录名： </label>
											<input name="account" type="text" class="form-data input-medium search-data">
										</label>
									</form>
								</div>
							</div>
						</div>
		
						<div>
							<div class="dataTables_wrapper form-inline no-footer">
								<table id="_table" class="table table-striped table-bordered table-hover dataTable no-footer">
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		</div>
		<jsp:include page="../common/bottom.jsp"></jsp:include>
		<script type="text/javascript">
			var scripts = [null, 
				"${_staticPath}/assets/js/bootbox.js?v=" + Math.random(),
				"${_staticPath}/script/assets/bootbox.custom.js?v=" + Math.random(),
				"${_staticPath}/script/jquery.form.min.js?v=" + Math.random(),
				"${_staticPath}/script/jquery.table.min.js?v=" + Math.random(),
				"${_staticPath}/assets/js/jquery.gritter.js?v=" + Math.random(),
				"${_staticPath}/script/assets/jquery.gritter.custom.js?v=" + Math.random(),
				null];
			$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
				jQuery(function($) {
					// 列表
		    		var $table = $("#_table").table({
		    			url : "${path}/admin/manager/list",
		    			formId : "_form",
						tools : [
							{text : '新增', clazz : 'btn-info', icon : 'fa fa-plus-circle blue', permission : '/admin/user/edit', handler : function(){
								window.location.href = "${path}/admin/manager/edit";
							}},
							{text : '禁用', clazz : 'btn-warning', icon : 'fa fa-lock orange', permission : '/admin/user/enable', handler : function(){
								$table.ajaxEnable({url : "${path}/admin/manager/enable"}, false);
							}},
							{text : '启用', clazz : 'btn-success', icon : 'fa fa-unlock green', permission : '/admin/user/enable', handler : function(){
								$table.ajaxEnable({url : "${path}/admin/manager/enable"}, true);
							}},
							{text : '删除', clazz : 'btn-danger', icon : 'fa fa-trash-o red', permission : '/admin/user/delete', handler : function(){
								$table.ajaxDelete({
									confirm : "删除管理员会影响关联的应用、角色、权限，确认要删除?",
									url : "${path}/admin/manager/delete"
								});
							}},
							{text : '重置密码', clazz : 'btn-default', icon : 'fa fa-key grey', permission : '/admin/user/resetPassword', handler : function(){
								$table.ajax({
									url : "${path}/admin/manager/resetPassword",
									confirm : "确认重置密码?",
									after : function(){
										$table.reload();
									}
								});
							}},
							{text : '分配角色', clazz : 'btn-default', icon : 'fa fa-cog grey', permission : '/admin/userApp/allocate', handler : function(){
								if(!$table.validateSelected(true)){
									return;						
								}
								window.location.href = "${path}/admin/manager/allocate?userId=" + $table.getSelectedItemKeys("id");
							}}
						],
						columns : [
					        {field:'id', hide : true},
					        {field:'isEnable', hide : true},
					        {field:'appId', hide : true},
					        {field:'account', title:'登录名', align:'left'},
					        {field:'loginCount', title:'登录总次数', mobileHide : true},
					        {field:'lastLoginIp', title:'最后登录IP', mobileHide : true},
					        {field:'lastLoginTime', title:'最后登录时间', mobileHide : true},
					        {field:'isEnableStr', title:'是否启用', replace : function (d){
						        if(d.isEnable)
						        	return "<span class='label label-sm label-success'>" + d.isEnableStr + 	"</span>";
					        	else
					        		return "<span class='label label-sm label-warning'>" + d.isEnableStr + "</span>";
					        }},
					        {field:'createTime', title:'创建时间', mobileHide : true}
						],
						operate : [
							{text : '修改', clazz : 'blue', icon : 'fa fa-pencil', permission : '/admin/user/edit', handler : function(d, i){
								window.location.href = "${path}/admin/manager/edit?id=" + d.id;
							}},
							{text : '禁用', clazz : 'orange', icon : 'fa fa-lock', permission : '/admin/user/enable', 
								handler : function(){
									$table.ajaxEnable({url : "${path}/admin/manager/enable"}, false);
								},
								show : function(d){
									return d.isEnable;
								}
							},
							{text : '启用', clazz : 'green', icon : 'fa fa-unlock', permission : '/admin/user/enable', 
								handler : function(){
									$table.ajaxEnable({url : "${path}/admin/manager/enable"}, true);
								},
								show : function(d){
									return !d.isEnable;
								}
							},
							{text : '删除', clazz : 'red', icon : 'fa fa-trash-o', permission : '/admin/user/delete', handler : function(d, i){
								$table.ajaxDelete({
									confirm : "删除管理员会影响关联的应用、角色、权限，确认要删除?",
									url : "${path}/admin/manager/delete"
								});
							}},
							{text : '重置密码', clazz : 'grey', icon : 'fa fa-key', permission : '/admin/user/resetPassword', handler : function(d, i){
								$table.ajax({
									url : "${path}/admin/manager/resetPassword",
									confirm : "确认重置密码?",
									after : function(){
										$table.reload();
									}
								});
							}},
							
							{text : '分配角色', clazz : 'grey', icon : 'fa fa-cog', permission : '/admin/userRole/allocate', handler : function(d, i){
								window.location.href = "${path}/admin/manager/allocate?userId=" + d.id;
							}}
						],
						after : function(){
							// 权限处理
							$.permission();
						}
					});
					
					//搜索
					$(".search-data").keyup(function () { 
						$table.search();
					});
					$("#_appId").change(function () { 
						$table.search();
		           	});
		            
					// 取消
					$("#_cancel").click(function(){
						$table.search();
					});
				});
			});
		</script>
		
	</body>
	
</html>

